% 这里由于ρ为1，我们直接用example5.19的正交基
x=0:0.5:10;
y=[2.9,2.7,4.8,5.3,7.1,7.6,7.7,7.6,9.4,9.0,9.6,10.0,10.2,9.7,8.3,8.4,9.0,8.3,6.6,6.7,4.1];
n=length(x);
%生成系数矩阵G
A=[ones(n, 1), x_data', x_data'.^2];
a1=21;
a2=sum(x);
a3=sum(x.^2);
a4=sum(x.^3);
a5=sum(x.^4);
G=[a1,a2,a3;a2,a3,a4;a3,a4,a5];
c1=sum(y);
c2=dot(y,x);
c3=dot(y,x.^2);
c=[c1;c2;c3];
a=inv(G)*c;
disp('系数为');
disp(['a0: ', num2str(a(1)), ', a1: ', num2str(a(2)), ', a2: ', num2str(a(3))]);
disp("函数表达式：-0.23844x^2+2.6704x+2.1757")

